package com.rjkj.medicalwaste.viewmodels

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.rjkj.medicalwaste.base.BaseViewModel
import com.rjkj.medicalwaste.network.response.catchException
import com.rjkj.medicalwaste.network.response.next
import kotlinx.coroutines.launch

class HomeViewModel :BaseViewModel(){
    val waitPack = MutableLiveData<Int>(0)
    val waitBoxNumber = MutableLiveData<Int>(0)
    val waitHandoverNumber = MutableLiveData<Int>(0)
    fun homeData(url:String,deviceSN:String,hospitalId:String){
       viewModelScope.launch {
            request(false) {
                getMedicalNumber(url = url,deviceSN = deviceSN,hospitalId = hospitalId)
            }.next {
                if(code==200){
                    if (data != null) {
                        waitBoxNumber.value = data.waitBoxNumber
                        waitPack.value = data.waitPack
                        waitHandoverNumber.value = data.waitHandoverNumber
                    }
                }else{
                    tips.value = message
                }
            }.catchException {

            }
       }
    }



}